# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=ixion
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.20.0
pkgrel=1
pkgdesc="A general purpose formula parser & interpreter. (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://gitlab.com/ixion/ixion'
msys2_references=(
  'archlinux: libixion'
)
license=('spdx:MPL-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-boost-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-mdds"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-vulkan-loader"
             "${MINGW_PACKAGE_PREFIX}-vulkan-headers")
optdepends=("${MINGW_PACKAGE_PREFIX}-python: Python bindings"
            "${MINGW_PACKAGE_PREFIX}-vulkan-loader: Vulkan compute engine")
source=("https://gitlab.com/ixion/ixion/-/archive/${pkgver}/${_realname}-${pkgver}.tar.bz2"
        "001-fix-build-on-mingw.patch"
        "002-do-not-search-for-boost-system.patch")
sha256sums=('39e54cd486fed458c2a6e83a5e658d4c2e818862355b33645bb1342449428463'
            'f5554b215c7be10f48a2567824acf54a7b97831b4e4723d76edd4fede31931fd'
            '0bef56f5fe568a3131d187c95d7efec62e8617f23e02c3c20b6642da1e195837')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-fix-build-on-mingw.patch
  patch -p1 -i "${srcdir}"/002-do-not-search-for-boost-system.patch

  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --enable-vulkan

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  make check || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" make install

  _pyver=$(${MINGW_PREFIX}/bin/python -c "import sys;sys.stdout.write('.'.join(map(str, sys.version_info[:2])))")
  # Use *.pyd extension for python module
  mv "${pkgdir}${MINGW_PREFIX}"/lib/python${_pyver}/site-packages/ixion.{dll,pyd}
  # remove unused import library
  rm -f "${pkgdir}${MINGW_PREFIX}"/lib/python${_pyver}/site-packages/ixion.dll.a

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
